package Thread;

import java.util.Scanner;
//内存可见性问题--->使用volatile进行解决
public class Demo13 {
    private static volatile int flag = 0;
    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            while (flag == 0){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                ;
            }
            System.out.println("t1线程执行结束");
        });
        Thread t2 = new Thread(()->{
            Scanner in = new Scanner(System.in);
            System.out.println("请输入flag的值:");
            flag = in.nextInt();
        });
        t1.start();
        t2.start();
    }
}
